# -*-  conding: utf-8 -*-
# Author: czh
# Datetime : 2022/5/10 11:07
from pprint import pprint

import tushare as ts
import time
# from datetime import datetime
import datetime
import tkinter as tk
import requests
import pysnowball as ball

pro = ts.pro_api('cf37ab059637ac7f5d628bdd046a9bcb2c1e34c2fa7546e6b8659225')

sysmbol_list = ['BJ430198',
                'BJ831305',
                'BJ831856',
                'BJ832145',
                'BJ832225',
                'BJ832885',
                'BJ834021',
                'BJ834475',
                'BJ835184',
                'BJ835640',
                'BJ836149',
                'BJ837242',
                'BJ838030',
                'BJ871396',
                'BJ871553',
                'BJ871981',
                'SH600012',
                'SH600019',
                'SH600076',
                'SH600088',
                'SH600121',
                'SH600123',
                'SH600135',
                'SH600141',
                'SH600149',
                'SH600156',
                'SH600178',
                'SH600198',
                'SH600201',
                'SH600203',
                'SH600215',
                'SH600217',
                'SH600232',
                'SH600235',
                'SH600256',
                'SH600262',
                'SH600269',
                'SH600282',
                'SH600288',
                'SH600298',
                'SH600309',
                'SH600315',
                'SH600370',
                'SH600372',
                'SH600376',
                'SH600383',
                'SH600397',
                'SH600398',
                'SH600400',
                'SH600406',
                'SH600408',
                'SH600423',
                'SH600439',
                'SH600448',
                'SH600476',
                'SH600507',
                'SH600508',
                'SH600511',
                'SH600526',
                'SH600546',
                'SH600557',
                'SH600561',
                'SH600567',
                'SH600612',
                'SH600617',
                'SH600618',
                'SH600645',
                'SH600713',
                'SH600722',
                'SH600727',
                'SH600736',
                'SH600750',
                'SH600758',
                'SH600770',
                'SH600774',
                'SH600826',
                'SH600841',
                'SH600843',
                'SH600844',
                'SH600848',
                'SH600866',
                'SH600867',
                'SH600889',
                'SH600892',
                'SH600963',
                'SH600968',
                'SH600971',
                'SH600981',
                'SH600985',
                'SH600988',
                'SH601001',
                'SH601006',
                'SH601038',
                'SH601088',
                'SH601101',
                'SH601188',
                'SH601319',
                'SH601326',
                'SH601339',
                'SH601718',
                'SH601777',
                'SH601799',
                'SH601808',
                'SH601857',
                'SH601866',
                'SH601872',
                'SH601898',
                'SH601918',
                'SH601933',
                'SH601975',
                'SH601996',
                'SH603022',
                'SH603028',
                'SH603037',
                'SH603045',
                'SH603048',
                'SH603056',
                'SH603070',
                'SH603115',
                'SH603129',
                'SH603139',
                'SH603168',
                'SH603177',
                'SH603180',
                'SH603219',
                'SH603226',
                'SH603268',
                'SH603277',
                'SH603317',
                'SH603324',
                'SH603338',
                'SH603353',
                'SH603358',
                'SH603393',
                'SH603398',
                'SH603477',
                'SH603518',
                'SH603530',
                'SH603558',
                'SH603567',
                'SH603568',
                'SH603595',
                'SH603608',
                'SH603610',
                'SH603665',
                'SH603687',
                'SH603737',
                'SH603768',
                'SH603825',
                'SH603833',
                'SH603836',
                'SH603868',
                'SH603882',
                'SH603889',
                'SH603915',
                'SH603917',
                'SH603949',
                'SH603950',
                'SH603955',
                'SH603979',
                'SH603993',
                'SH605007',
                'SH605018',
                'SH605066',
                'SH605077',
                'SH605123',
                'SH605183',
                'SH605189',
                'SH605208',
                'SH605369',
                'SH605377',
                'SH605577',
                'SH605599',
                'SH688021',
                'SH688066',
                'SH688068',
                'SH688087',
                'SH688133',
                'SH688180',
                'SH688181',
                'SH688198',
                'SH688201',
                'SH688212',
                'SH688228',
                'SH688288',
                'SH688310',
                'SH688314',
                'SH688316',
                'SH688317',
                'SH688368',
                'SH688513',
                'SH688520',
                'SH688606',
                'SH688607',
                'SH688639',
                'SH688683',
                'SH688685',
                'SZ000001',
                'SZ000016',
                'SZ000048',
                'SZ000059',
                'SZ000069',
                'SZ000070',
                'SZ000096',
                'SZ000422',
                'SZ000423',
                'SZ000429',
                'SZ000526',
                'SZ000552',
                'SZ000637',
                'SZ000639',
                'SZ000672',
                'SZ000678',
                'SZ000700',
                'SZ000703',
                'SZ000711',
                'SZ000716',
                'SZ000720',
                'SZ000800',
                'SZ000822',
                'SZ000825',
                'SZ000830',
                'SZ000882',
                'SZ000895',
                'SZ000913',
                'SZ000950',
                'SZ000968',
                'SZ000976',
                'SZ000985',
                'SZ001267',
                'SZ001313',
                'SZ002030',
                'SZ002040',
                'SZ002064',
                'SZ002087',
                'SZ002094',
                'SZ002095',
                'SZ002109',
                'SZ002128',
                'SZ002145',
                'SZ002146',
                'SZ002170',
                'SZ002179',
                'SZ002210',
                'SZ002228',
                'SZ002250',
                'SZ002262',
                'SZ002269',
                'SZ002282',
                'SZ002287',
                'SZ002293',
                'SZ002333',
                'SZ002352',
                'SZ002353',
                'SZ002357',
                'SZ002367',
                'SZ002369',
                'SZ002375',
                'SZ002378',
                'SZ002384',
                'SZ002400',
                'SZ002415',
                'SZ002425',
                'SZ002430',
                'SZ002448',
                'SZ002458',
                'SZ002479',
                'SZ002505',
                'SZ002508',
                'SZ002510',
                'SZ002511',
                'SZ002517',
                'SZ002521',
                'SZ002526',
                'SZ002539',
                'SZ002541',
                'SZ002552',
                'SZ002555',
                'SZ002611',
                'SZ002612',
                'SZ002614',
                'SZ002644',
                'SZ002645',
                'SZ002658',
                'SZ002659',
                'SZ002661',
                'SZ002679',
                'SZ002702',
                'SZ002729',
                'SZ002731',
                'SZ002737',
                'SZ002778',
                'SZ002786',
                'SZ002788',
                'SZ002793',
                'SZ002802',
                'SZ002816',
                'SZ002828',
                'SZ002839',
                'SZ002867',
                'SZ002868',
                'SZ002871',
                'SZ002882',
                'SZ002888',
                'SZ002901',
                'SZ002919',
                'SZ002956',
                'SZ002966',
                'SZ002991',
                'SZ002995',
                'SZ003030',
                'SZ300010',
                'SZ300026',
                'SZ300167',
                'SZ300171',
                'SZ300194',
                'SZ300254',
                'SZ300267',
                'SZ300294',
                'SZ300298',
                'SZ300324',
                'SZ300375',
                'SZ300407',
                'SZ300417',
                'SZ300426',
                'SZ300436',
                'SZ300442',
                'SZ300489',
                'SZ300511',
                'SZ300573',
                'SZ300596',
                'SZ300622',
                'SZ300627',
                'SZ300633',
                'SZ300643',
                'SZ300645',
                'SZ300651',
                'SZ300673',
                'SZ300711',
                'SZ300731',
                'SZ300760',
                'SZ300777',
                'SZ300796',
                'SZ300829',
                'SZ300857',
                'SZ300960',
                'SZ300987',
                'SZ300993',
                'SZ301017',
                'SZ301066',
                'SZ301092',
                'SZ301093',
                'SZ301108',
                'SZ301113',
                'SZ301187',
                'SZ301206',
                'SZ301235',
                'SZ301256']

# def jisuan(open, low, current, name, float_market_capital):
#     """ 计算下影线 / 柱体 大于2.5"""
#     shiti = max(open, current) - min(open, current)
#     xiaying = min(open, current) - low
#     # 流通值在150亿以上， 去除ST
#     if shiti == 0.0 or xiaying == 0.0 and float_market_capital < 15000000000 and "ST" not in name:
#         # print("跳过：", shiti, xiaying)
#         pass
#     else:
#         jieguo = round(xiaying / shiti, 2)
#         # L <= O * 0.95 and C >= L * 1.05;
#         # low * 1.06 < min(open, close)
#         if jieguo > 2.5:
#             print(name, jieguo)
#             return jieguo


if __name__ == '__main__':
    new_sysmbol_list = []
    start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    print(start_time)
    for sysmbol in sysmbol_list:
        sysmbol = sysmbol[:8]
        name = sysmbol[8:]
        try:
            res = ball.quotec(sysmbol)
            print(res)
            float_market_capital = float(res["data"][0]["float_market_capital"])
            if float_market_capital < 15000000000:
                new_sysmbol_list.append(name)
        except TypeError:
            print("出现异常：", sysmbol)
    print(len(new_sysmbol_list))
    pprint(new_sysmbol_list)
    end_time = cur_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    print(end_time)
    # # 获取所有股票
    # start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    # print(start_time)
    # df = pro.query('stock_basic', exchange='', list_status='L', fields='ts_code,name')
    # for idx, data in df.iterrows():
    #     # 循环调用接口
    #     code = data[0][-2:] + data[0][:6]
    #     name = data[1]
    #     try:
    #         res = ball.quotec(code)
    #         current = float(res["data"][0]["current"])
    #         open = float(res["data"][0]["open"])
    #         low = float(res["data"][0]["low"])
    #         float_market_capital = float(res["data"][0]["float_market_capital"])
    #         # cur_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    #         # 获取符合结果
    #         # jisuan(open, low, current, name, float_market_capital)
    #         # pprint(res)
    #
    #
    #     except TypeError:
    #         print("出现异常：", name)
    #
    # end_time = cur_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    # print(end_time)
